#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 3e5 + 10;
struct node
{
	int v;
	int idx;
}S[N], S1[N];
int a1[N];
int n, k;
int cmp(node A, node B)
{
	if (A.v != B.v)return A.v > B.v;
	return A.idx < B.idx;
}

int cmp2(node A, node B)
{
	if (A.v != B.v)return A.v > B.v;
	return A.idx < B.idx;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		scanf("%d%d", &n, &k);
		bool flag = 0;
		int cnt1 = 0, cnt2 = 0;
		for (int i = 1; i <= n; i++) {
			int x;
			scanf("%d", &x);
			int a = x % k;
			if (a == 0) {
				a1[++cnt1] = i;
			}
			else {
				S[++cnt2] = { a,i };
			}
		}
		/*if (!flag) {
			sort(S1 + 1, S1 + n + 1, cmp2);
			for (int i = 1; i <= n; i++) {
				printf("%d ", S1[i].idx);
			}
			printf("\n");
			continue;
		}*/
		sort(a1 + 1, a1 + cnt1 + 1);
		sort(S + 1, S + cnt2 + 1, cmp);
		//cout<<"cnt1=="<<cnt1<<endl;
		//cout<<"cnt2=="<<cnt2<<endl;
		for (int i = 1; i <= cnt1; i++) {
			printf("%d ", a1[i]);
		}
		for (int i = 1; i <= cnt2; i++) {
			printf("%d ", S[i].idx);
		}
		/*priority_queue<PII>heap;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			heap.push({ a[i],i });
		}
		if (k == 1) {
		}
		vector<int>ans;x
		while (heap.size()) {
			PII t1 = heap.top();
			heap.pop();

		}*/
		// 		for (int i = 1; i <= n; i++) {
		// 			printf("%d ", S[i].idx);
		// 		}
		printf("\n");
	}
	return 0;
}